home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / PixelWorld classes 1.2 / CPixelWorldPane.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-30  |  5.1 KB  |  206 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.  CPixelWorldPane.c
  3.  
  4.                             The PixelWorldPane Class
  5.     
  6.     The CPixelWorldPane class is a subclass of CPanorama that uses a 
  7.     CPixelWorld object to display a color or grayscale image that is 
  8.     kept offscreen.  An offscreen color graphics device (GDevice) and an 
  9.     offscreen color graphics port (CGrafPort) are used to maintain this 
  10.     offscreen world.  This implementation supports 1,2,4 and 8 bit pixel 
  11.     depths.  Pixel depths of 16 and 32 bits are not currently supported.  
  12.     
  13.     This implementation does not depend upon any 32-Bit QuickDraw features.  
  14.     Future versions of the CPixelWorld class will provide support for pixel 
  15.     depths of 16 and 32 bits, and for GWorlds under 32-Bit QuickDraw.  
  16.     
  17.     SUPERCLASS = CPanorama
  18.     
  19.     This implementation is based in part on material copyrighted by 
  20.     Symantec Corporation and Apple Computer, Inc.  
  21.     
  22.     Copyright © 1992 Vincent R. Vann, Jr.  All rights reserved.  
  23.     
  24.     Version 1.2 Changes:
  25.     [
  26.         - changed class definition to make the superclass CPanorama 
  27.           instead of CBitMapPane as in the original implementation.  
  28.         - modified the SetPixelWorld method so that the bounds, position, 
  29.           and origin of the PixelWorldPane are changed to reflect the 
  30.           new PixelWorld's coordinates.  This method also refreshes the 
  31.           pane so that the image of the new PixelWorld will be drawn.  
  32.     ]
  33.     
  34.  ******************************************************************************/
  35.  
  36. #include "CPixelWorldPane.h"
  37. #include "Exceptions.h"
  38. #include "Global.h"
  39. #include "LongQD.h"
  40.  
  41.  
  42. /**** C O N S T R U C T I O N / D E S T R U C T I O N   M E T H O D S ****/
  43.  
  44.  
  45. /******************************************************************************
  46.  IPixelWorldPane
  47.  
  48.         Initialize a PixelWorldPane object
  49.  ******************************************************************************/
  50.  
  51. void    CPixelWorldPane::IPixelWorldPane(
  52.     CView            *anEnclosure,
  53.     CBureaucrat        *aSupervisor,
  54.     short            aWidth,
  55.     short            aHeight,
  56.     short            aHEncl,
  57.     short            aVEncl,
  58.     SizingOption    aHSizing,
  59.     SizingOption    aVSizing,
  60.     LongRect        *aBounds,
  61.     CPixelWorld        *aPixelWorld)
  62. {
  63.     itsPixelWorld = NULL;
  64.     
  65.     CPanorama::IPanorama(
  66.             anEnclosure, aSupervisor, aWidth, aHeight, 
  67.             aHEncl, aVEncl, aHSizing, aVSizing);
  68.     
  69.     bounds = *aBounds;
  70.     
  71.     position.h = bounds.left;
  72.     position.v = bounds.top;
  73.     
  74.     itsPixelWorld = aPixelWorld;
  75.     
  76.     IPixelWorldPaneX();
  77. }
  78.  
  79.  
  80. void    CPixelWorldPane::IPixelWorldPaneX()
  81. {
  82.     if (itsPixelWorld == NULL)        /* Create a default pixel world */
  83.     {
  84.         Rect            r;
  85.         LongRect        lRect;
  86.         GDHandle        gdev;
  87.         PixMapHandle    pmap;
  88.         short            depth;
  89.         
  90.         if (gSystem.hasColorQD)        /* World has color */
  91.         {
  92.             r = (**GrayRgn).rgnBBox;    /* Use rect that covers all screens */
  93.             
  94.             gdev = GetMaxDevice( &r);    /* Get device with max pixel depth */
  95.             pmap = (**gdev).gdPMap;        /* Get the device's PixMap */
  96.             depth = (**pmap).pixelSize;    /* Get the device's pixel depth */
  97.             
  98.             if (depth > 8)                /* Pixel depth must be <= 8 */
  99.                 depth = 8;
  100.         }
  101.         else                        /* World is black and white */
  102.         {
  103.             depth = 1;                    /* Use pixel depth of 1 */
  104.         }
  105.         
  106.         lRect = bounds;
  107.         LongToQDRect( &lRect, &r);
  108.         
  109.         itsPixelWorld = new( CPixelWorld);
  110.         itsPixelWorld->IPixelWorld( depth, &r, NULL, NULL, 0);
  111.     }
  112.     
  113.     autoRefresh = FALSE;
  114. }
  115.  
  116.  
  117. /******************************************************************************
  118.  Dispose {OVERRIDE}
  119.  
  120.         Dispose of a PixelWorldPane
  121.  ******************************************************************************/
  122.  
  123. void    CPixelWorldPane::Dispose()
  124. {
  125.     if (itsPixelWorld != NULL)
  126.     {
  127.         itsPixelWorld->Dispose();
  128.         itsPixelWorld = NULL;
  129.     }
  130.     
  131.     inherited::Dispose();
  132. }
  133.  
  134.  
  135. /******************************************************************************
  136.  GetPixelWorld
  137.  
  138.         Return a reference to the PixelWorld associated with a PixelWorldPane
  139.  ******************************************************************************/
  140.  
  141. CPixelWorld*    CPixelWorldPane::GetPixelWorld()
  142. {
  143.     return( itsPixelWorld);
  144. }
  145.  
  146.  
  147. /******************************************************************************
  148.  SetPixelWorld
  149.  
  150.         Specify the PixelWorld associated with a PixelWorldPane
  151.  ******************************************************************************/
  152.  
  153. void    CPixelWorldPane::SetPixelWorld(
  154.     CPixelWorld*    aPixelWorld)
  155. {
  156.     if (aPixelWorld != itsPixelWorld)
  157.     {
  158.         LongRect    lRect;
  159.         LongPt        lPt;
  160.         
  161.         itsPixelWorld = aPixelWorld;
  162.         
  163.         if (aPixelWorld != NULL)
  164.             aPixelWorld->GetBounds( &lRect);
  165.         else
  166.             SetLongRect( &lRect, 0, 0, 0, 0);
  167.         
  168.         lPt.h = lRect.left;
  169.         lPt.v = lRect.top;
  170.         
  171.         SetFrameOrigin( lRect.left, lRect.top);
  172.         SetBounds( &lRect);
  173.         SetPosition( &lPt);
  174.         
  175.         Refresh();
  176.     }
  177. }
  178.  
  179.  
  180. /******************************************************************************
  181.  Draw {OVERRIDE}
  182.  
  183.         Draw a PixelWorldPane
  184.  ******************************************************************************/
  185.  
  186. void    CPixelWorldPane::Draw(
  187.     Rect        *area)
  188. {
  189.     LongRect    lBounds, lArea;
  190.     Rect        bounds;
  191.     
  192.     if (itsPixelWorld != NULL)
  193.     {
  194.         itsPixelWorld->GetBounds( &lBounds);
  195.         LongToQDRect( &lBounds, &bounds);
  196.         
  197.         SectRect(area, &bounds, area);
  198.         QDToFrameR( area, &lArea);
  199.         
  200.         itsPixelWorld->CopyFrom( &lArea, &lArea, NULL);
  201.     }
  202.     else
  203.         EraseRect( area);
  204. }
  205.  
  206.